import { Schema, model,Document,Types } from 'mongoose'
import { TopicSchema } from './topics'

export interface UserSchema extends Document {
  name?: string
  password?: string
  avatar_url?: string
  headline?: string
  description?: string
  business?: string
  employments?: string
  homepage?: string
  following?: Types.ObjectId[]
  followingTopics?: Types.ObjectId[]
}

const userSchema = new Schema({
  __v: { type: Number, select: false },
  name: { type: String, required: true },
  password: { type: String, required: true, select: false },
  avatar_url: { type: String },
  headline: { type: String },
  description: { type: String },
  business: { type: String },
  employments: { type: String },
  homepage: { type: String },
  following: {
    type: [{ type: Schema.Types.ObjectId, ref: 'User' }],
    select: false,
  },
  followingTopics: {
    type: [{ type: Schema.Types.ObjectId, ref: 'Topic' }],
    select: false,
  },
})

export default model<UserSchema>('User', userSchema)
